# -*- coding: utf-8 -*-            
# @Time : 2023/7/24 22:29
# @Author  : lining
# @FileName: n叉树先序遍历.py
"""
https://leetcode.cn/problems/n-ary-tree-preorder-traversal/
"""
class Node():
    def __init__(self, value=0):
        """
        :param value:
        :param child: 列表形式，可存放多个子节点
        """
        self.value = value
        self.child = []


result = []
def Traversal(node):
    """
    :param node: 开始访问的节点
    :return:
    """
    if node is None:
        return
    result.append(node.value)
    for i in node.child:
        Traversal(i)



node = Node(1)
node1 = Node(2)
node2 = Node(3)
node3 = Node(4)
node4 = Node(5)
node5 = Node(6)
node6 = Node(7)
node7 = Node(8)
node8 = Node(9)
node9 = Node(10)
node10 = Node(11)
node11 = Node(12)
node12 = Node(13)
node.child.extend([node1,node2,node3,node4])
node2.child.extend([node5,node6,node7,node8])
node6.child.extend([node9,node10,node11,node12])
"""
                           1
              2        3        4       5
                6     7      8    9
                  10,11,12,13
"""
Traversal(node)
print(result)